include(@CMAKE_SOURCE_DIR@/cmake/Utils.cmake)

get_git_describe("@GIT_EXECUTABLE@" "@CMAKE_SOURCE_DIR@" GIT_DESCRIBE)
get_app_version(GIT_DESCRIBE APP_VERSION_YEAR APP_VERSION_NUMBER APP_VERSION_RC)
get_app_version_str(APP_VERSION_YEAR APP_VERSION_NUMBER APP_VERSION_RC APP_VERSION_STR)
set(APP_BUILD_TYPE "@CMAKE_BUILD_TYPE@")

set(MANUAL_VERSION_PATTERN "__TB_VERSION__")
set(MANUAL_BUILD_ID_PATTERN "__TB_BUILD_ID__")

file(READ "${INPUT}" MANUAL_CONTENTS)
string(REGEX REPLACE "${MANUAL_VERSION_PATTERN}" "${APP_VERSION_STR}" MANUAL_CONTENTS "${MANUAL_CONTENTS}")
string(REGEX REPLACE "${MANUAL_BUILD_ID_PATTERN}" "${GIT_DESCRIBE} ${APP_BUILD_TYPE}" MANUAL_CONTENTS "${MANUAL_CONTENTS}")
file(WRITE "${OUTPUT}" "${MANUAL_CONTENTS}")
